package edu.neusoft.android.yuejian14.model;


import edu.neusoft.android.yuejian14.service.RetrofitService;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static edu.neusoft.android.yuejian14.Const_Service.BASE_URL;


public class UserModel {
    private static Retrofit retrofit;
    public UserModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    //登录
    public static Call login(String str_user, String str_userpassword){
       RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        return  retrofitService.userLogin(str_user,str_userpassword);
//        call.enqueue(new Callback<User>() {
//            @Override
//            public void onResponse(Call<User> call, Response<User> response) {
//                User sampleLogin=response.body();
//                listener.onSuccess(sampleLogin,1);
//            }
//            @Override
//            public void onFailure(Call<User> call, Throwable t) {
//                listener.onFail();
//            }
//        });
    }
    //注册
        public Call register(String strUsername, String str_username, String str_userpassword){
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        return retrofitService.userRegister(str_username,str_userpassword);
    }

    public Call getUserById(int uid){
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        return retrofitService.getUserById(uid);
    }

    //用户详情
    public Call getUserInfo(int uid) {
        RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        return retrofitService.getUserInfo(uid);
    }

}
